<?php
namespace app\index\controller;

use app\BaseController;
use app\model\Cdkey;
use app\model\Notice;
use app\model\User;
use think\facade\Db;
use app\model\Version;

class Index extends BaseController
{
    public function index()
    {
        return '123';
    }
    
    
    public function siteInfo()
    {
        $contactus = Notice::where("id",3)->field("val as is_enable, content, img_url")->find();
        
        $contactus['img_url'] = getHost() . $contactus['img_url'];
        return success([
            "contactus" => $contactus
        ]);
    }

    //检测用户的卡密时间是否为1天
    public function check()
    {
        //不限制时间
        set_time_limit(0);
        //获取所有用户的卡密
        $userCdkey = User::field('id,cdkey')->select();
        foreach ($userCdkey as $k=>$v)
        {
            //获取时长
            $cdkey = $v['cdkey'];
            $cdkeyInfo = Cdkey::where('cdkey',$cdkey)->find();
            if($cdkeyInfo['time']==1)
            {
                //1天为测试数据，需要删除
                User::where('id',$v['id'])->delete();
                //删除卡密
                Cdkey::where('cdkey',$cdkey)->delete();
                //收入删除
                Db::name('income')->where('uid',$v['id'])->delete();
                Db::name('profit_log')->where('uid',$v['id'])->delete();
                Db::name('transfer')->where('uid',$v['id'])->delete();
            }
        }


    }


    //版本
    public function version()
    {
        $res = Version::where('id', 1)->find();
        return success($res);
    }


    //活动规则描述
    public function getRule()
    {
        $info = Db::name('rule')->where('id', 1)->find();
        return success($info);
    }

    //提现金额设置
    public function getMoney()
    {
        $info = Db::name('transfer_list')->select();
        return success($info);
    }

}
